package ui.component
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	import flashx.textLayout.formats.TextAlign;
	
	public class ParameterValue extends Sprite
	{
		public var type:uint;
		
		private var _title:String;
		private var _titleText:TextField;
		
		private var _value:int=0;
		private var _maxValue:int=0;
		private var _valueText:TextField;
		
		private var _string:String;
		
		private var _background:Bitmap;
		private var _width:Number;
		private var _height:Number;
		
		private var _valueSize:int;
		private var _titleSize:int;
		/////////////////////////////////////////////////
		

		public function get string():String
		{
			return _string;
		}

		public function set string(value:String):void
		{
			_string = value;
			
			if(type==2)
			{
				_valueText.text = value;
			}
		}

		override public function get height():Number
		{
			return _height;
		}

		override public function set height(value:Number):void
		{
			_height = value;
			updateSize();
		}

		override public function get width():Number
		{
			return _width;
		}

		override public function set width(value:Number):void
		{
			_width = value;
			updateSize();
		}

		public function get value():int
		{
			return _value;
		}

		public function set value(value:int):void
		{
			_value = value;
			
			if(type==1)
			{
				_valueText.text = String(_value)+"/"+String(_maxValue);
			}else if(type==0)
			{
				_valueText.text = String(_value);
			}
		}

		public function get maxValue():int
		{
			return _maxValue;
		}

		public function set maxValue(value:int):void
		{
			if(type==1)
			{
				_maxValue = value;
				_valueText.text = String(_value)+"/"+String(_maxValue);
			}
		}

		public function get title():String
		{
			return _title;
		}

		public function set title(value:String):void
		{
			_title = value;
			_titleText.text = value;
		}
		
		/////////////////////////////////////////////////
		
		/**
		 * @param Type 0:只有一个值的参数；1：包括当前值与最大值的参数；2：字符串参数
		 */
		public function ParameterValue(Type:int=-1,Width:Number=139,Height:Number=46)
		{
			type = Type;
			_width = Width;
			_height = Height;
			
			_titleText = new TextField;
			_valueText = new TextField;
			
			_background = new Bitmap;
			updateSize();
			
			_titleText.textColor = _valueText.textColor = 0xdddddd;
			
			var format:TextFormat = new TextFormat("Microsoft YaHei");
			format.align = TextAlign.LEFT;
			_titleText.defaultTextFormat = format;
			
			format = new TextFormat("Microsoft YaHei");
			format.align = TextAlign.RIGHT;
			_valueText.defaultTextFormat = format;
			
			_titleText.mouseEnabled = _valueText.mouseEnabled = false;
			
			addChild(_background);
			addChild(_titleText);
			addChild(_valueText);
		}
		
		private function updateSize():void
		{
			var backBmd:BitmapData = new BitmapData(_width,_height,true,0x88000000);
			_background.bitmapData = backBmd;
			
			_valueText.x = _width-100;
			_valueText.y = _height-22;
		}
		

	}
}